<template>
	<!-- jurisdiction人员权限 -->
	<view class="j_wp">
		<checkbox-group @change="checkboxChange">
			<label class="j_label" v-for="item in plist" :key="item.value">
				<view class="j_item">
					<checkbox class="j_checkbox" :value="item.value" :checked="item.checked" />{{item.name}}
				</view>
			</label>
		</checkbox-group>
		<view class="J_Range">
			<text>权限范围：</text>
			<radio-group class="j_r_radio-group" @change="radioChange">
				<label class="j_r_label" v-for="(item, index) in RangeList" :key="item.value">
					<radio class="j_checkbox" color="#8405dc" :value="item.value" :checked="index == range" />
					{{item.name}}
				</label>
			</radio-group>
		</view>
		<view class="j_submit" @click="onsumbit">
			确认提交
		</view>
		<bottom-tab />
	</view>
</template>

<script>
	import BottomTab from '@/components/bottomtab.vue';
	export default {
		components: {
			BottomTab
		},
		data() {
			return {
				uid: '',
				mid: '',

				my: [],
				plist: [],

				range: '0',
				RangeList: [{
						value: '0',
						name: '所属店铺'
					},
					{
						value: '1',
						name: '所有店铺'
					}
				]
			}
		},
		onLoad(option) {
			this.uid = option.uid;
			this.mid = option.id;
			this.getPowe();
		},
		methods: {
			getPowe() {
				this.$axios('groupManager/myPower', 'POST', 'supplier', {
					mid: this.mid
				}).then(res => {
					if (res.data.code == 200) {
						var data = res.data.data;
						this.my = data.my;
						this.range = data.range;
						this.plist = data.plist.map(v => {
							v.checked = false;
							for (let i in data.my) {
								if (data.my[i] == v.id) {
									v.checked = true;
									break;
								}
							}
							return {
								value: v.id,
								name: v.name,
								checked: v.checked
							};
						})
					}
				})
			},
			onsumbit() {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认提交？',
					success(e) {
						if (e.confirm) {
							that.$axios('groupManager/savePower', 'POST', 'supplier', {
								range: that.range,
								powers: that.my,
								mid: that.mid
							}).then(res => {
								if (res.data.code == 200) {
									that.$api.msg(res.data.data);
									setTimeout(() => {
										that.$navRed(
											'/pages/groupmenu/personnellist?isback=1&uid=' +
											that.uid)
									}, 500)
								}
							})
						}
					}
				})

			},
			radioChange(e) {
				this.range = e.detail.value;
			},
			checkboxChange(e) {
				this.my = e.detail.value;
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f2f2f2;
		padding-bottom: 130upx;
	}

	.j_label {
		display: block;
		padding-top: 20upx;
	}

	.j_item,
	.J_Range,
	.j_r_radio-group {
		background-color: #fff;
		display: flex;
		align-items: center;
		padding: 20upx;
	}

	.j_checkbox {
		transform: scale(0.8);
	}

	.J_Range {
		margin-top: 20upx;
	}

	.j_r_radio-group {
		padding: 0;
	}

	.j_r_label {
		margin-right: 20upx;
	}

	.j_submit {
		background-color: $base-color;
		border-radius: 40upx;
		color: #fff;
		line-height: 70upx;
		margin: 40upx auto;
		text-align: center;
		width: 96%;
	}
</style>
